package com.eeGroup.service;

import com.eeGroup.controller.AuthController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@Configuration
@PropertySource("classpath:dict.properties")
public class DictConfig {
    static Logger logger = LoggerFactory.getLogger(DictConfig.class);

    @Autowired
    private Environment environment;

    private Map<String, String> dictMap = new HashMap<>();

    public DictConfig() {
        try {
            // 加载properties文件
            Resource resource = new ClassPathResource("dict.properties");
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            properties.forEach((key, value) -> dictMap.put(key.toString(), value.toString()));
        } catch (IOException e) {
            logger.error(e.getMessage(),e);
        }
    }

    public Map<String, String> getDictMap() {
        return dictMap;
    }
}
